using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ClipLink
{
	public class BrowserForm : System.Windows.Forms.Form
	{
		private AxSHDocVw.AxWebBrowser axWebBrowser1;

		private System.ComponentModel.Container components = null;

		private string url = "";

		public BrowserForm (string url)
		{
			this.url = url;
			InitializeComponent();
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(BrowserForm));
			this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
			((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();
			this.SuspendLayout();
			// 
			// axWebBrowser1
			// 
			this.axWebBrowser1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.axWebBrowser1.Enabled = true;
			this.axWebBrowser1.Location = new System.Drawing.Point(0, 0);
			this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));
			this.axWebBrowser1.Size = new System.Drawing.Size(640, 280);
			this.axWebBrowser1.TabIndex = 0;
			// 
			// BrowserForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(640, 278);
			this.Controls.Add(this.axWebBrowser1);
			this.Name = "BrowserForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "DictGadget";
			this.Load += new System.EventHandler(this.BrowserForm_Load);
			((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/*[STAThread]
		static void Main() 
		{
			Application.Run(new BrowserForm());
		}*/

		private void BrowserForm_Load(object sender, System.EventArgs e)
		{
			object empty = System.Reflection.Missing.Value;
			//axWebBrowser1.Navigate("about:blank", ref empty, ref empty, ref empty, ref empty);

			//setBrowserHtml("<font face=\"Arial\" size=2>Web browser demo. Visit <a href=\"http://www.ryanfarley.com/\" target=_blank>ryanfarley.com</a> for more.</font><br><br><a href=\"http://www.ryanfarley.com/\" border=0><img src=\"http://ryanfarley.com/Skins/RyanFarleyBlue2/Images/RyanFarley-Title_bg.jpg\" border=0></a>");
			axWebBrowser1.Navigate(url, ref empty, ref empty, ref empty, ref empty);
		}

		private void setBrowserHtml(string html)
		{
			// create an IHTMLDocument2
			mshtml.IHTMLDocument2 doc = axWebBrowser1.Document as mshtml.IHTMLDocument2;

			// write to the doc
			doc.clear();
			doc.writeln(html);

			doc.close();
		}

		private void btnPrint_Click(object sender, System.EventArgs e)
		{
			mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2) axWebBrowser1.Document;
			doc.execCommand("Print", true, 0);
		}
	}
}
